package framework.common.zanetwork;

import java.util.List;

public class UrlBuilder {

    public static String buildUrl(String actionUrl, List<String> pathParams) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(actionUrl);
        String url = stringBuilder.toString();

        String[] urlArr = url.split("/");
        String newUrl = "";
        for (int i = 0; i < urlArr.length; i++) {
            if (urlArr[i].contains("{id}")) {
                for (int j = 0; j < pathParams.size(); j++) {
                    urlArr[i] = pathParams.get(j);
                    pathParams.remove(j);
                }
            }
            newUrl += urlArr[i] + "/";
        }
        newUrl = newUrl.substring(0, newUrl.length() - 1);
        return newUrl;
    }
}
